#region Microsoft Public License
/*
 * (c) Copyright Chenjun Wu. http://utablesdk.codeplex.com
 * 
 * This source is subject to the Microsoft Public License (Ms-PL).
 * Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
 * All other rights reserved.
 */
#endregion

﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UTable.Objects
{
    public class UBookPreview: UObjectPreview
    {
        protected UBookModel Model = new UBookModel();

        public override object GetModel()
        {
            return this.Model.Clone();
        }

        public override void UpdateModel(object updateMessage)
        {
            Console.WriteLine(this + ": " + updateMessage);
            if (updateMessage is SetFolderPathMessage || updateMessage is OpenBookMessage)
            {
                this.Model.Clear();
                this.Model.FolderPath = (updateMessage as SetFolderPathMessage).FolderPath;
                this.FolderPath = Model.FolderPath;
            }
            else if (updateMessage is UpdataBookAnnotationMessage)
            {
                // update the annotation
            }
        }

        public override void InitializeModel(object model)
        {
            UBookModel source = model as UBookModel;
            if (source != null)
            {
                this.Model = new UBookModel(source);
                this.FolderPath = source.FolderPath;
            }
        }
    }
}
